#define CATCH_CONFIG_MAIN
#include <iostream>
#include "catch.hpp"
#include "coherentElastic/coherentElastic_util/bccLatticeFactors.h"
#include "generalTools/testing.h"

TEST_CASE( "taubcc" ){
  GIVEN( "inputs" ){
    std::vector<std::tuple<int,int,int,double>> inputs
      { {0,0,0,2}, {1,0,0,2}, {0,1,0,2}, {0,0,1,2}, {1,1,0,2},
        {1,0,1,2}, {0,1,1,2}, {1,1,1,2}, {1,2,3,4}, {5,3,6,4},
        {8,7,9,.1} };
    std::vector<double> output { 0, 78.956835, 78.956835, 78.956835, 236.870506,
      236.870506, 236.870506, 473.741011, 3947.84176, 21002.518165, 1519.9191 };
    
    for ( size_t i = 0; i < output.size(); ++i ){
      REQUIRE( taubcc( std::get<0>(inputs[i]), std::get<1>(inputs[i]),
                       std::get<2>(inputs[i]), std::get<3>(inputs[i])) ==
               Approx(output[i]).epsilon(1e-6) );
    }
  } // GIVEN
} // TEST CASE



TEST_CASE( "Function to Compute BCC Lattice Factors (i.e. iron)" ){
  double maxTauSq = 5.79115688E19, a = 2.86e-8;
  int lat = 6;
  std::vector<double> b (60000, 0.0), bVec1(100), bVec2(100), bVec3(100);
  int imax = bccLatticeFactors( maxTauSq, b, lat, a);
  bVec1 = { 5.733821E19, 5.28248E-10, 5.511804E19, 5.38782E-10, 5.309093E19, 
  5.48971E-10, 5.125688E19, 5.58706E-10, 4.961589E19, 5.67870E-10, 4.816796E19, 
  5.76342E-10, 4.691308E19, 5.84000E-10, 4.585126E19, 5.90723E-10, 4.498250E19, 
  5.96400E-10, 4.430680E19, 6.00931E-10, 4.382415E19, 6.04231E-10, 4.353456E19, 
  6.06237E-10, 4.343804E19, 6.06910E-10, 5.569721E19, 5.35973E-10, 5.338052E19, 
  5.47480E-10, 5.125688E19, 5.58706E-10, 4.932630E19, 5.69535E-10, 4.758878E19, 
  5.79839E-10, 4.604432E19, 5.89483E-10, 4.469291E19, 5.98329E-10, 4.353456E19, 
  6.06237E-10, 4.256928E19, 6.13072E-10, 4.179704E19, 6.18710E-10, 4.121787E19, 
  6.23041E-10, 4.083175E19, 6.25980E-10, 4.063870E19, 6.27465E-10, 4.063870E19, 
  6.27465E-10, 5.685556E19, 5.30485E-10, 5.424928E19, 5.43079E-10, 5.183606E19, 
  5.55576E-10, 4.961589E19, 5.67870E-10, 4.758878E19, 5.79839E-10, 4.575473E19, 
  5.91346E-10, 4.411374E19, 6.02244E-10, 4.266580E19, 6.12378E-10, 4.141093E19, 
  6.21587E-10, 4.034911E19, 6.29713E-10, 3.948035E19, 6.36604E-10, 3.880465E19, 
  6.42122E-10, 3.832200E19, 6.46153E-10, 3.803241E19, 6.48609E-10, 3.793588E19, 
  6.49433E-10, 3.803241E19, 6.48609E-10, 5.569721E19, 5.35973E-10, 5.299440E19, 
  5.49471E-10, 5.048465E19, 5.62963E-10, 4.816796E19, 5.76342E-10, 4.604432E19, 
  5.89483E-10, 4.411374E19, 6.02244E-10, 4.237622E19, 6.14467E-10 }; 
  bVec2 = { 3.455737E19, 6.80439E-10, 3.272332E19, 6.99248E-10, 3.108233E19, 
  7.17469E-10, 2.963439E19, 7.34787E-10, 2.837952E19, 7.50857E-10, 2.731770E19, 
  7.65311E-10, 2.644894E19, 7.77778E-10, 2.577323E19, 7.87908E-10, 2.529059E19, 
  7.95390E-10, 2.500100E19, 7.99984E-10, 2.490447E19, 8.01532E-10, 2.500100E19, 
  7.99984E-10, 2.529059E19, 7.95390E-10, 2.577323E19, 7.87908E-10, 2.644894E19, 
  7.77778E-10, 5.627639E19, 5.33208E-10, 5.280135E19, 5.50474E-10, 4.951936E19, 
  5.68424E-10, 4.643043E19, 5.87027E-10, 4.353456E19, 6.06237E-10, 4.083175E19, 
  6.25980E-10, 3.832200E19, 6.46153E-10, 3.600531E19, 6.66617E-10, 3.388167E19, 
  6.87191E-10, 3.195109E19, 7.07647E-10, 3.021357E19, 7.27711E-10, 2.866910E19, 
  7.47055E-10, 2.731770E19, 7.65311E-10, 2.615935E19, 7.82071E-10, 2.519406E19, 
  7.96913E-10, 2.442183E19, 8.09414E-10, 2.384266E19, 8.19186E-10, 2.345654E19, 
  8.25901E-10, 2.326348E19, 8.29321E-10, 2.326348E19, 8.29321E-10, 2.345654E19, 
  8.25901E-10, 2.384266E19, 8.19186E-10, 2.442183E19, 8.09414E-10, 2.519406E19, 
  7.96913E-10, 5.656598E19, 5.31841E-10, 5.299440E19, 5.49471E-10, 4.961589E19, 
  5.67870E-10, 4.643043E19, 5.87027E-10, 4.343804E19, 6.06910E-10, 4.063870E19, 
  6.27465E-10, 3.803241E19, 6.48609E-10, 3.561919E19, 6.70220E-10, 3.339902E19, 
  6.92138E-10, 3.137191E19, 7.14150E-10, 2.953786E19, 7.35987E-10 };
  bVec3 = { 4.150746E18, 1.963346E-9, 5.502151E18, 1.705272E-9, 7.046615E18, 
  1.506849E-9, 8.784136E18, 1.349617E-9, 1.071472E19, 1.221996E-9, 1.283835E19, 
  1.116363E-9, 1.515505E19, 1.027499E-9, 1.766480E19, 9.51712E-10, 2.036761E19, 
  8.86318E-10, 2.326348E19, 8.29321E-10, 1.911274E19, 9.14952E-10, 1.650645E19, 
  9.84539E-10, 1.409323E19, 1.065503E-9, 1.187306E19, 1.160857E-9, 9.845955E18, 
  1.274768E-9, 8.011904E18, 1.413163E-9, 6.370912E18, 1.584744E-9, 4.922977E18, 
  1.802794E-9, 3.668101E18, 2.088523E-9, 2.606282E18, 2.477703E-9, 1.737521E18, 
  3.034554E-9, 1.061819E18, 3.881815E-9, 5.791738E17, 5.256002E-9, 2.895869E17, 
  7.433110E-9, 1.930579E17, 9.103663E-9, 2.895869E17, 7.433110E-9, 5.791738E17, 
  5.256002E-9, 1.061819E18, 3.881815E-9, 1.737521E18, 3.034554E-9, 2.606282E18, 
  2.477703E-9, 3.668101E18, 2.088523E-9, 4.922977E18, 1.802794E-9, 6.370912E18, 
  1.584744E-9, 8.011904E18, 1.413163E-9, 9.845955E18, 1.274768E-9, 1.187306E19, 
  1.160857E-9, 1.409323E19, 1.065503E-9, 1.650645E19, 9.84539E-10, 1.911274E19, 
  9.14952E-10, 2.191208E19, 8.54512E-10, 2.490447E19, 8.01532E-10, 1.805092E19, 
  9.41478E-10, 1.554116E19, 1.014655E-9, 1.322447E19, 1.099945E-9, 1.110083E19, 
  1.200555E-9, 9.170252E18, 1.320898E-9, 7.432731E18, 1.467188E-9, 5.888267E18, 
  1.648414E-9, 4.536862E18, 1.877942E-9, 3.378514E18, 2.176192E-9 };
  REQUIRE( imax == 28079 );
  checkPartOfVec(b,bVec1,0);
  checkPartOfVec(b,bVec2,300);
  checkPartOfVec(b,bVec3,30000);
  restAreZero(56161,b);

} // TEST CASE

